<?php

namespace app\index\controller;

use think\App;
use think\Controller;
use think\Db;
use think\Request;

class SysConfig extends Base
{

    public function __construct(App $app = null)
    {
        parent::__construct($app);
    }

    /** 首页
     * @return mixed
     */
    public function index(Request $request){
        if($request->isPost()){
            Db::name("config")->where("name","web_site_title")->update(["value"=>$request->post('web_site_title')]);
            Db::name("config")->where("name","web_site_copyright")->update(["value"=>$request->post('web_site_copyright')]);
            Db::name("config")->where("name","web_site_icp")->update(["value"=>$request->post('web_site_icp')]);
            return $this->success("保存成功");
        }
        $dbConfig=Db::name("config")->select();
        $config=[
            'web_site_title'=>$dbConfig[0]['value'],
            'web_site_copyright'=>$dbConfig[1]['value'],
            'web_site_icp'=>$dbConfig[2]['value'],
        ];
        $this->assign("config",$config);
        return $this->fetch();
    }

}
